#region 模块信息
// **********************************************************************
// 作者(Author):                  GUO
// 创建时间(CreateTime):           2019/3/22 11:58:50
// **********************************************************************
#endregion
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 继承自MonoBehaviour的泛型单例
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingletonMono<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T mInstance;
    private static readonly object mLocker=new object();

    public static T Instance
    {
        get
        {
            if (mInstance == null)
            {
                lock (mLocker)
                {
                    if (mInstance == null)
                    {
                        GameObject obj=new GameObject(typeof(T).Name);
                        return obj.AddComponent<T>();
                    }
                }
            }
            return mInstance;
        }
    }

    void Awake()
    {
        OnAwake();
    }

    void Start()
    {
        OnStart();
    }

    void OnEnable()
    {
        OnEnableStart();
    }
    void Update()
    {
        OnUpdate();
    }

    void OnDisable()
    {
        BeforeOnDisable();
    }
    void OnDestroy()
    {
        BeforeOnDestroy();
    }
    protected virtual void OnStart() { }
    protected virtual void OnEnableStart() { }
    protected virtual void OnAwake() { }
    protected virtual void OnUpdate() { }
    protected virtual void BeforeOnDisable() { }
    protected virtual void BeforeOnDestroy() { }
}
